<?php
// +----------------------------------------------------------------------
// | 版权所有 2010~2023 重庆小奇迹科技有限公司 [ http://www.yuuyoo.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://www.szn.com
// +----------------------------------------------------------------------
// | 开源协议 ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | github开源项目：https://gitee.com/lishikeji/lishi
// +----------------------------------------------------------------------
namespace app\traits;

use app\model\Log as Model;

/*
 * 操作日志服务
 */
trait Log
{
    /*
     * 写入操作日志
     * @param string $action
     * @param string $content
     * @return bool
     */
    public static function write($action = '行为', $content = "内容描述")
    {
        $request = request();
        $node = strtolower(join('/', [$request->module(), $request->controller(), $request->action()]));
        $data = [
            'ip'       => $request->ip(),
            'node'     => $node,
            'action'   => $action,
            'content'  => $content,
            'username' => session('user.username') . '',
        ];
        return Model::create($data) !== false;
    }

}
